﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BooksOnline.Models.Entities;
using BooksOnline.Repositories.Base;
using NHibernate;
using NHibernate.Criterion;

namespace BooksOnline.Repositories
{
    public class BookRepository : RepositoryBase<Book>
    {
        public IList<Book> ByTitle(string title)
        {
            return
                DetachedCriteria
                    .For<Book>()
                    .Add(Restrictions.Like("Title", title))
                    .GetExecutableCriteria(CurrentSession)
                    .List<Book>();
        }

        public IList<Book> ByAuthor(string authorName)
        {
            return
                DetachedCriteria
                    .For<Book>()
                    .CreateAlias("Author","auth")
                    .Add(Restrictions.Like("auth.Name", authorName))
                    .GetExecutableCriteria(CurrentSession)
                    .List<Book>();
        }
    }
}